package com.oocl.client;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

import com.oocl.command.Command;
import com.oocl.command.CommandResolver;
import com.oocl.command.executor.CommandExecutor;
import com.oocl.command.executor.CommandExecutorImpl;
import com.oocl.exception.MyException;

public class SCPClient {
	
	
     public static void main(String[] args) throws UnknownHostException, IOException {
    	 Socket socket=new Socket("127.0.0.1",8888);
 		OutputStream out=socket.getOutputStream();
 		InputStream in=socket.getInputStream();
 		BufferedReader reader=new BufferedReader(new InputStreamReader(in));
 		String conrs = reader.readLine();
 		System.out.println(conrs);
 		Scanner scanner=new Scanner(System.in);
 		CommandExecutor cmdexe = new CommandExecutorImpl();
 		while(true){
      	   String commandStr = scanner.nextLine();
      	   Command cmd = CommandResolver.resoleCommand(commandStr);
      	   if(cmd==null){
      		   String mes = "not exist command '"+commandStr+"'";
      		   System.out.println(mes);
      		   continue;
      	   }else{
      		   try{
      			   cmdexe.sovleCommand(reader, out, cmd);
      		   }catch(Exception e){
      			   if(e instanceof MyException){
      				   continue;
      			   }
      		   }
      	   }
      	   
         }
 		
 		
 		
   }
     
     
}
